<?php 
include("includes/code_admin.php");
if (isset($_GET['id'])) {$id = $_GET['id'];}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<title><?php echo SITEURL; ?> Administrator</title>
<link href="style_admin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="script.js"></script>

</head>

<body>
<div id="container">
<table class="main" cellspacing="0" cellpadding="0">
  <tr>
    <td class="header">
    <!-- header start -->
    <?php include("includes/header.php");?>
    <!-- header finish -->
    </td>
  </tr>
  <tr>
    <td class="middle">&nbsp;</td>
  </tr>
  <tr>
    <td>
    <!-- tepa start -->
<?php include("includes/tepa.php"); ?>
    <!-- tepa finish -->
    </td>
  </tr>
  <tr>
    <td>
    <!-- contant start -->
<table class="content" cellspacing="0" cellpadding="0">
  <tr valign="top">
    <td>
    <!-- right col -->
<div class="right_col">
<h3 class="title">Tovarni O'zgartirish</h3>

<? 
// tekshiramiz
if(isset($_POST['send']))
{
$id = $_POST['id'];
$cat = $_POST['cat'];
$main = $_POST['main'];
$title = trim($_POST['title']);
$text = trim($_POST['text']);
$price = $_POST['price'];
$date = $_POST['date'];
$view = $_POST['view'];
// rasmlar esa
$img_link_thumb = $_POST['img_mini']; 
$img_link = $_POST['img'];
$img_link2 = $_POST['img2'];
$img_link3 = $_POST['img3'];

$title = addslashes($title);
$text = addslashes($text);
$price = addslashes($price);
 
/*tekshir*/
 	if(trim($cat) == '')
    {
      $error = ' Kategoriyani tanlang ';
    }
	else if(trim($title) == '')
    {
      $error = ' Sarlavhani yozing';
    }
    else if(trim($text) == '')
    {
       $error = ' Matn yozmadingiz!';
    }
	if($error == '')
	{
	/****** RASM YUKLASH KODI *****/
	include("includes/img_uploader.php");
	/***** RASM YUKLASH KODI TAMOM ******/

	$result = mysql_query("UPDATE data SET cat='$cat', title='$title', text='$text', price='$price', date='$date', custom='$main',   view='$view', img_mini='$img_link_thumb', img='$img_link',  img2='$img_link2', img3='$img_link3' WHERE id='$id'");
	 if($result=='true') 
	 { 
	 echo "<p class='ok'>Malumot qo'shildi, OK. ... ".$yuklandi.$yuklandi2.$yuklandi3."</p>";
	 echo $yuklanmadi.$yuborilmadi.$yuborilmadi2.$yuborilmadi3;
	 echo "<br><center><a href = 'tovar_main.php'><b>Yana O'zgartirish</b></a>";
	 }
	 else 
	 { 
	 echo "<p class='error'>DIQQAT! Afsuski Tovaringiz qo'shilmadi... Qayta kiriting yoki adminga xabar bering</p>"; 
	 }
	}
}

if(!isset($_POST['send']) || $error != '')
{
// bazadan tovar haqida malumot olamiz
$result = mysql_query("SELECT id,cat,title,text,date,price,img_mini,img,img2,img3,custom,view FROM data WHERE id='$id' ",$db);
$myrow = mysql_fetch_array($result);
// kategoriyalarni olamiz
$result2 = mysql_query("SELECT title,id FROM menu",$db);
$myrow2 = mysql_fetch_array($result2);
?>

<fieldset>
<legend style="color:#728D9E">Mavjud tovarni o'zgartirish</legend>
<? if($error) echo "<p class='error'>$error </p>";  ?>
<form name="myform" action="" method="post" enctype="multipart/form-data" onsubmit="return tekshir(this)">
<table width="600" border="0" cellspacing="7" cellpadding="3">
  <tr>
    <td width="100" class="r">Kategoriya</td>
    <td>
<select name="cat" style="width:200px;">
<option value="">-- Tanlang --</option>
<?  
do
{
	if($myrow['cat'] == $myrow2['id'])
	{ 
	printf("<option value='%s' selected> %s </option>", $myrow2["id"], $myrow2["title"]); 
	}
	else
	{
	printf("<option value='%s'> %s </option>", $myrow2["id"], $myrow2["title"]);
	}
}
while($myrow2 = mysql_fetch_array($result2));
?>
</select>
 &nbsp; 
<label>
<?php 
if($myrow["custom"] == 'main') { $checked = "checked"; }
?>
<input name="main" type="checkbox" value="main" <?php echo $checked ?> /> Bosh sahifada ham ko'rinsinmi
</label>
    </td>
  </tr>
  <tr>
    <td  class="r">Sarlavha</td>
    <td><input type="text" name="title" size="50" value="<? echo stripslashes($myrow["title"]); ?>"/></td>
  </tr>
  <tr>
    <td class="r">Text</td>
    <td><textarea name="text" cols="60" rows="8"><? echo stripslashes($myrow["text"]); ?></textarea></td>
  </tr>
  <tr>
    <td class="r">Narx</td>
    <td><input type="text" name="price" size="20" maxlength="15" value="<? echo $myrow["price"]; ?>" /></td>
  </tr>
  <tr>
    <td class="r">Foto</td>
    <td><input type="file" name="file" size="30" /></td>
  </tr>
  <tr bgcolor="#D9DCDF">
    <td height="65" class="r">Foto 2 <br />  Foto 3 
     </td>
    <td>
    <input type="file" name="file2" size="30" /><br />
	<input type="file" name="file3" size="30" />
    </td>
  </tr>
  <tr bgcolor="#D9DCDF">
    <td height="65" class="r">Mavjud Rasmlar 
     </td>
    <td>
    img_mini, img, img2, img3 <br><br>
    <input type="text" name="img_mini" size="15" value="<?php echo $myrow["img_mini"]; ?>"/>
    <input type="text" name="img" size="15" value="<?php echo $myrow["img"]; ?>"/>
    <input type="text" name="img2" size="15" value="<?php echo $myrow["img2"]; ?>"/>
    <input type="text" name="img3" size="15" value="<?php echo $myrow["img3"]; ?>"/>
    </td>
  </tr>
  <tr>
    <td class="r">Vaqt (Bugun)</td>
    <td>
    <input type="text" name="date" size="20" value="<?php echo date("d-F, Y") ?>"/> &nbsp; 
    Ko'rilganlar soni: <input type="text" name="view" size="4" value="<?php echo $myrow["view"]; ?>"/>
    <br />
	<input type="hidden" name="id" value="<? echo $myrow["id"]; ?>" />
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="send" value=" Yuborish " /></td>
  </tr>
</table>
</form>
</fieldset>
<?php 
}
?>
</div>
	<!-- right col finish -->
    </td>
  </tr>
</table>
    <!-- contant finish -->
    </td>
  </tr>
</table>
<!-- futer start -->
<?php include("includes/futer.php"); ?>
<!-- futer finish -->
</div>
</body>
</html>
